#include "ColorForm.h"
#include "ui_ColorForm.h"

ColorForm::ColorForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ColorForm)
{
    ui->setupUi(this);

    connect(ui->boxRed,     SIGNAL(valueChanged(double)), SLOT(componentChanged(double)));
    connect(ui->boxGreen,   SIGNAL(valueChanged(double)), SLOT(componentChanged(double)));
    connect(ui->boxBlue,    SIGNAL(valueChanged(double)), SLOT(componentChanged(double)));
}

ColorForm::~ColorForm()
{
    delete ui;
}

void ColorForm::initColor(const QVector3D &color)
{
    ui->boxRed  ->setValue(static_cast<double>(color.x()));
    ui->boxGreen->setValue(static_cast<double>(color.y()));
    ui->boxBlue ->setValue(static_cast<double>(color.z()));
}

QVector3D ColorForm::color() const
{
    return QVector3D(static_cast<float>(ui->boxRed->value()),
                     static_cast<float>(ui->boxGreen->value()),
                     static_cast<float>(ui->boxBlue->value()));
}

void ColorForm::componentChanged(double value)
{
    Q_UNUSED(value)

    emit colorChanged(QVector3D(static_cast<float>(ui->boxRed->value()),
                                static_cast<float>(ui->boxGreen->value()),
                                static_cast<float>(ui->boxBlue->value())));
}
